CFLAGS+=$(shell pkg-config --cflags dbus-1)
LDFLAGS+=$(shell pkg-config --libs dbus-1)

CFLAGS+=-Isrc/include -I./3rd/include
LDFLAGS+=-lpthread  -Wl,-Bstatic -lev -L ./3rd/lib -Wl,-Bdynamic -lm

all: dbus_client dbus_server

commmon_h=$(wildcard src/include/*.h)
dbus_client_file=src/dbus_client.c src/at_dbus.c src/tests.c src/dbus_test_comm_loop.c
dbus_server_file=src/dbus_server.c src/at_dbus.c src/tests.c src/dbus_test_comm_loop.c

dbus_client: $(dbus_client_file) $(commmon_h)
	$(CC) $(CFLAGS) -DTEST_CLIENT -o $@  $(filter-out %.h, $^) $(LDFLAGS) -g

dbus_server: $(dbus_server_file) $(commmon_h)
	$(CC) $(CFLAGS) -DTEST_SERVER -o $@  $(filter-out %.h, $^) $(LDFLAGS) -g

.PHONY: clean distclean mem

.PHONY += libev
build/libev-4.33:
	tar xf libev-4.33.tar.gz -C $(@D)
	@cd $(@) && ./configure --prefix=$(CURDIR)/3rd
	@cd $(@) && $(MAKE) -j 4 && $(MAKE) install

libev:: build/libev-4.33

distclean:clean

clean:
	rm -rf dbus_client dbus_server

mem:
	@for i in `pidof dbus_server`;do echo "pidof dbus_server Proc_id:$$i"; cat /proc/$$i/status | grep Vm;done
	@for i in `pidof dbus_client`;do echo "pidof dbus_client Proc_id:$$i"; cat /proc/$$i/status | grep Vm;done
